Add a menu position function for use with popups on status icons.
authorMatthias Clasen <mclasen@redhat.com>
Sat, 29 Apr 2006 06:34:14 +0000 (06:34 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 29 Apr 2006 06:34:14 +0000 (06:34 +0000)
2006-04-29  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkstatusicon.h:
* gtk/gtkstatusicon.c (gtk_status_icon_position_menu): Add a menu
position function for use with popups on status icons.  (#334573,
Christian Persch)

ChangeLog
ChangeLog.pre-2-10
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtkstatusicon.c
gtk/gtkstatusicon.h

index bfd2895a5350e80df2387dfd41e7882761478c2c..0923e566f244170cd20da8a1f1abbfce9c5e06d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2006-04-29  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkstatusicon.h: 
+       * gtk/gtkstatusicon.c (gtk_status_icon_position_menu): Add a menu
+       position function for use with popups on status icons.  (#334573, 
+       Christian Persch)
+
        * gtk/gtkwidget.c (gtk_widget_is_composited): Fix a C99ism.  (#340055,
        Kazuki Iwamoto)
 
index bfd2895a5350e80df2387dfd41e7882761478c2c..0923e566f244170cd20da8a1f1abbfce9c5e06d0 100644 (file)
@@ -1,5 +1,11 @@
 2006-04-29  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkstatusicon.h: 
+       * gtk/gtkstatusicon.c (gtk_status_icon_position_menu): Add a menu
+       position function for use with popups on status icons.  (#334573, 
+       Christian Persch)
+
        * gtk/gtkwidget.c (gtk_widget_is_composited): Fix a C99ism.  (#340055,
        Kazuki Iwamoto)
 
index e68e35a55591d1bdf77cb346c9ef1becb15ae8f2..700249068b08fa76c5065f24b3af3c16b18c19e5 100644 (file)
@@ -1,3 +1,7 @@
+2006-04-29  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk-sections.txt: Add gtk_status_icon_position_menu
+
 2006-04-25  Matthias Clasen  <mclasen@redhat.com>
 
        * gdk/gdk-sections.txt: Add gdk_screen_is_composited
index d5acc625dca0ada1aedaafb20c2854cfdaf8d4d8..0744b6b7e3c614a2b78c2066de799f8b3ea43ed4 100644 (file)
@@ -3240,6 +3240,7 @@ gtk_status_icon_get_visible
 gtk_status_icon_set_blinking
 gtk_status_icon_get_blinking
 gtk_status_icon_is_embedded
+gtk_status_icon_position_menu
 <SUBSECTION Standard>
 GTK_TYPE_STATUS_ICON
 GTK_STATUS_ICON
index 4a2614bc0203211f477978023fbf5c82ab95e581..e4fba9775db54a3c3d7f78189e317291d7ea2467 100644 (file)
@@ -1050,6 +1050,7 @@ gtk_status_icon_get_visible
 gtk_status_icon_set_blinking
 gtk_status_icon_get_blinking
 gtk_status_icon_is_embedded
+gtk_status_icon_position_menu
 #endif
 #endif
 
index b38f7cde72ca67f09cb4e94dfcaeda415d9b8725..9a37f4fd9b5aa5e97af51825cca01eaabf4adcc5 100755 (executable)
@@ -1469,5 +1469,113 @@ gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
 #endif
 }
 
+/**
+ * gtk_status_icon_position_menu:
+ * @menu: the #GtkMenu
+ * @x: return location for the x position
+ * @y: return location for the y position
+ * @push_in: return location for whether the menu should be pushed in 
+ *     to be completely inside the screen instead of just clamped to the 
+ *     size to the screen.
+ * @user_data: the status icon to position the menu on
+ *
+ * Menu positioning function to use with gtk_menu_popup()
+ * to position @menu aligned to the status icon @user_data.
+ * 
+ * Since: 2.10
+ **/
+void
+gtk_status_icon_position_menu (GtkMenu  *menu,
+                              gint     *x,
+                              gint     *y,
+                              gboolean *push_in,
+                              gpointer  user_data)
+{
+#ifdef GDK_WINDOWING_X11
+  GtkStatusIcon *status_icon;
+  GtkStatusIconPrivate *priv;
+  GtkTrayIcon *tray_icon;
+  GtkWidget *widget;
+  GdkScreen *screen;
+  GtkTextDirection direction;
+  GtkRequisition menu_req;
+  GdkRectangle monitor;
+  gint monitor_num, height, width, xoffset, yoffset;
+  
+  g_return_if_fail (GTK_IS_MENU (menu));
+  g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
+
+  status_icon = GTK_STATUS_ICON (user_data);
+  priv = status_icon->priv;
+  tray_icon = GTK_TRAY_ICON (priv->tray_icon);
+  widget = priv->tray_icon;
+
+  direction = gtk_widget_get_direction (widget);
+
+  screen = gtk_widget_get_screen (widget);
+  gtk_menu_set_screen (menu, screen);
+
+  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+  if (monitor_num < 0)
+    monitor_num = 0;
+  gtk_menu_set_monitor (menu, monitor_num);
+
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  gdk_window_get_origin (widget->window, x, y);
+  
+  gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
+
+  if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
+    {
+      width = 0;
+      height = widget->allocation.height;
+      xoffset = widget->allocation.width;
+      yoffset = 0;
+    }
+  else
+    {
+      width = widget->allocation.width;
+      height = 0;
+      xoffset = 0;
+      yoffset = widget->allocation.height;
+    }
+
+  if (direction == GTK_TEXT_DIR_RTL)
+    {
+      if ((*x - (menu_req.width - width)) >= monitor.x)
+        *x -= menu_req.width - width;
+      else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
+        *x += xoffset;
+      else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
+        *x -= menu_req.width - width;
+      else
+        *x += xoffset;
+    }
+  else
+    {
+      if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
+        *x += xoffset;
+      else if ((*x - (menu_req.width - width)) >= monitor.x)
+        *x -= menu_req.width - width;
+      else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
+        *x += xoffset;
+      else 
+        *x -= menu_req.width - width;
+    }
+
+  if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
+    *y += yoffset;
+  else if ((*y - (menu_req.height - height)) >= monitor.y)
+    *y -= menu_req.height - height;
+  else if (monitor.y + monitor.height - (*y + yoffset) > *y)
+    *y += yoffset;
+  else 
+    *y -= menu_req.height - height;
+
+  *push_in = FALSE;
+#endif /* GDK_WINDOWING_X11 */
+}
+
 #define __GTK_STATUS_ICON_C__
 #include "gtkaliasdef.c"
index c810dac1bf94ebd6dcbe8aeff29b2b9012043615..265b006e53f4787e1582307632a9cf4ee3616448 100755 (executable)
@@ -25,6 +25,7 @@
 #define __GTK_STATUS_ICON_H__
 
 #include <gtk/gtkimage.h>
+#include <gtk/gtkmenu.h>
 
 G_BEGIN_DECLS
 
@@ -103,6 +104,12 @@ gboolean              gtk_status_icon_get_blinking       (GtkStatusIcon      *st
 
 gboolean              gtk_status_icon_is_embedded        (GtkStatusIcon      *status_icon);
 
+void                  gtk_status_icon_position_menu      (GtkMenu            *menu,
+                                                         gint               *x,
+                                                         gint               *y,
+                                                         gboolean           *push_in,
+                                                         gpointer            user_data);
+
 G_END_DECLS
 
 #endif /* __GTK_STATUS_ICON_H__ */